package models

import (
	"gorm.io/gorm"
	"zk507/common/inits"
	"zk507/common/proto/user"
)

type Information struct {
	gorm.Model
	InformationName string `gorm:"type:varchar(30);comment:'名称'"`
	Address         string `gorm:"type:varchar(150);comment:'地址"`
	Scale           int64  `gorm:"type:int(10);comment:'规模 人数'"`
}

func (*Information) TableName() string {
	return "information"
}

func (i *Information) GetList() (list []*Information, err error) {
	if err = inits.DB.Debug().Find(&list).Error; err != nil {
		return nil, err
	}
	return list, nil
}

func (i *Information) GetFormationList(address string, scale int64) (list []*user.List, err error) {
	var tion []*Information
	if err = inits.DB.Debug().Where("address=? and scale=?", address, scale).Find(&tion).Error; err != nil {
		return nil, err
	}
	for _, m := range tion {
		list = append(list, &user.List{
			InformationName: m.InformationName,
			Address:         m.Address,
			Scale:           m.Scale,
		})
	}
	return list, nil
}
